home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / swtools / mipsABI / examples / sup / skipto.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  2.9 KB  |  79 lines

  1. /*
  2.  * Copyright (c) 1991 Carnegie Mellon University
  3.  * All Rights Reserved.
  4.  * 
  5.  * Permission to use, copy, modify and distribute this software and its
  6.  * documentation is hereby granted, provided that both the copyright
  7.  * notice and this permission notice appear in all copies of the
  8.  * software, derivative works or modified versions, and any portions
  9.  * thereof, and that both notices appear in supporting documentation.
  10.  *
  11.  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
  12.  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
  13.  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  14.  *
  15.  * Carnegie Mellon requests users of this software to return to
  16.  *
  17.  *  Software Distribution Coordinator   or   Software.Distribution@CS.CMU.EDU
  18.  *  School of Computer Science
  19.  *  Carnegie Mellon University
  20.  *  Pittsburgh PA 15213-3890
  21.  *
  22.  * any improvements or extensions that they make and grant Carnegie the rights
  23.  * to redistribute these changes.
  24.  */
  25. /************************************************************************
  26.  *  skipover and skipto -- skip over characters in string
  27.  *
  28.  *  Usage:    p = skipto (string,charset);
  29.  *        p = skipover (string,charset);
  30.  *
  31.  *  char *p,*charset,*string;
  32.  *
  33.  *  Skipto returns a pointer to the first character in string which
  34.  *  is in the string charset; it "skips until" a character in charset.
  35.  *  Skipover returns a pointer to the first character in string which
  36.  *  is not in the string charset; it "skips over" characters in charset.
  37.  ************************************************************************
  38.  * HISTORY
  39.  * 26-Jun-81  David Smith (drs) at Carnegie-Mellon University
  40.  *    Skipover, skipto rewritten to avoid inner loop at expense of space.
  41.  *
  42.  * 20-Nov-79  Steven Shafer (sas) at Carnegie-Mellon University
  43.  *    Skipover, skipto adapted for VAX from skip() and skipx() on the PDP-11
  44.  *    (from Ken Greer).  The names are more mnemonic.
  45.  *
  46.  *    Sindex adapted for VAX from indexs() on the PDP-11 (thanx to Ralph
  47.  *    Guggenheim).  The name has changed to be more like the index()
  48.  *    and rindex() functions from Bell Labs; the return value (pointer
  49.  *    rather than integer) has changed partly for the same reason,
  50.  *    and partly due to popular usage of this function.
  51.  */
  52.  
  53. static unsigned char tab[256] = {
  54.     0};
  55.  
  56. char *skipto (string,charset)
  57. unsigned char *string, *charset;
  58. {
  59.     register unsigned char *setp,*strp;
  60.  
  61.     tab[0] = 1;        /* Stop on a null, too. */
  62.     for (setp=charset;  *setp;  setp++) tab[*setp]=1;
  63.     for (strp=string;  tab[*strp]==0;  strp++)  ;
  64.     for (setp=charset;  *setp;  setp++) tab[*setp]=0;
  65.     return ((char *)strp);
  66. }
  67.  
  68. char *skipover (string,charset)
  69. unsigned char *string, *charset;
  70. {
  71.     register unsigned char *setp,*strp;
  72.  
  73.     tab[0] = 0;        /* Do not skip over nulls. */
  74.     for (setp=charset;  *setp;  setp++) tab[*setp]=1;
  75.     for (strp=string;  tab[*strp];  strp++)  ;
  76.     for (setp=charset;  *setp;  setp++) tab[*setp]=0;
  77.     return ((char *)strp);
  78. }
  79.